

import Vue from "vue";

// 页码相关
let page = {
  // total: 1,
  startIndex: 0,
  stepNumber: 30,
  // currentPage: 1,
  // totlaPage:1
};

let searchInfoPage ={
  total: 1,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1
};


//页面状态相关
let status = {
  modalMessage:{
    isShow:false,
    type:0
  },
  modalImage: {
    isShow: false,
    url: ''
  },
  modalAction:{
    isShow:false,
  },
  modalSearchInfo: {
    isShow:false,
    showTableType:1, //显示表格。产品：1；订单：2；购物车：3；登录记录：4
  },
  modalAssignUser:{
    isShow: false
  },
  modalStatusChange:{
    isShow: false,
    state:-1
  },
  modalModifyStatusNote: {
    isShow: false,
  },
  modalProductSupply: {
    isShow: false,
  },
  modalEmail: {
    isShow: false,
  },
  isShowFullName:false,
  modalSendEmail: {
    isShow: false,
    emailContent:"",
    emailTitle:"",
    users:[],
    email:""
  }
};

// 和网络交互相关的参数
let params = {
  messageSendParam: {
    userId: "",
    userName: "",
    token: "",
    content: "",
    picUrl:"",
    ossId:'',
    type:''
  },
  searchInfoParam: {
    serialNumber:"",
    userId:"",
    productCode:""
  },
  messageStatusParam: {
    userId:"",
    employeeId:"",
    employeeName:"",
    state:0,
  },
  statusParam: {
    userId: "",
    statusId:"",
    state:0,
  },
  noteParam: "",
  selectedTags: [],
  userEmailParam: {
    id: "",
    userId: "",
    email: "",
    note: "",
    createtime: null,
  }
};

// 页面的数据源
let data = {
  messageList: [],
  messageUserInfo:{
    userName:'',
    userCode:'',
    country:'',
    deviceType:'',
    version:'',
    registertime:'',
    registerType:'',
    orderCount:0,
    cartCount:0,
    tabId:[],
    // userNote:''
    email: "",
  },
  productList:[],
  orderList:[],
  cartList:[],
  tabList:[],
  cartWeightCount:"",
  cartPriceCount:"",
  recordList:[],
  messageStatus: {
    id: null,
    userId: null,
    employeeId: null,
    state: null,
    loadedMessageId: "",
    lastLoadTime: null,
    lastReaderId: null,
    createtime: null,
    employeeName: "",
    tags: "",
    note: "",
  },
  tagList: [
    {
      value: '普通咨询',
      label: '普通咨询'
    },
    {
      value: '定制服务',
      label: '定制服务'
    }, {
      value: '一件代发',
      label: '一件代发'
    },
    {
      value: '咨询关税',
      label: '咨询关税'
    },
    {
      value: '账号问题',
      label: '账号问题'
    },
    {
      value: '售后-催单',
      label: '售后-催单'
    },
    {
      value: '售后-物流跟踪',
      label: '售后-物流跟踪'
    },
    {
      value: '售后-损坏',
      label: '售后-损坏'
    },
    {
      value: '售后-未收到包裹',
      label: '售后-未收到包裹'
    },
    {
      value: '售后-欠货退款',
      label: '售后-欠货退款'
    }
  ],
  productSupplyList: [],
  userEmail: {
    id: "",
    userId: "",
    email: "",
    note: "",
    createtime: null,
  },
};

let productTable = function (self) {
  return [
    {
      type: 'index',
      title: '#',
      width: 60,
      key: 'index',
      align: 'center',
    },
    {
      title: 'SKU',
      key: 'code',
      width: 200,
      align: 'center',
      render: (h, params) => {
        let productUrl = Vue.prototype.$tiyProductUrl(params.row.code);
        return h('div',[h('a',{
          attrs:{href:productUrl,target:'_blank'}
        },params.row.code)]);
      }
    },
    {
      title: '产品图片',
      key: 'listImgUrl',
      width: 130,
      render: (h, params) => {
        let yunPath = Vue.prototype.$store.getters.imgPrefix;
        let imageUrl = params.row.productImg;
        return !imageUrl ? '' : h('img', {
          attrs: {src: imageUrl, height: 60},
          on: {
            click: () => {
              status.modalImage.url = imageUrl;
              status.modalImage.isShow = true;
            }
          }
        })
      },
      align: 'center'
    },
    {
      title: '价格',
      key: 'prices',
      width: 150,
      align: 'center',
      render: (h, params) => {
        let price = "$" + params.row.currentPrice;
        if(params.row.minPrice){
          price = "$"+params.row.minPrice+" - "+ price;
        }
        return h('div', price);
      }
    },
    {
      title: '创建时间',
      key: 'createtime',
      sortable: 'custom',
      width: 150,
      render: (h, params) => {
        let date = new Date(params.row.createtime);
        return h('div',self.$tiyBJTime(params.row.createtime));
      },
      align: 'center'
    },
    {
      title: "上/下架时间",
      key: 'lastmodify',
      sortable: 'custom',
      width: 150,
      render: (h, params) => {
        return h('div',self.$tiyBJTime(params.row.lastmodify));
      },
      align: 'center'
    },
    {
      title: '操作',
      key: 'action',
      width: 100,
      render: (h, params) => {
        return self.$authority('PRODUCT-1-210')? h('Button', {
          props: {type: 'primary', size: 'small', icon: "md-create"},
          style: {marginRight: '10px',marginTop:'6px',marginBottom:'6px'},
          on: {
            click: () => {
              self.editItem(params.index);
            }
          }
        }, '编辑') : h('div','');
      },
      align: 'center'
    }
  ];
};

let orderTable = function (self) {
  return [
    {
      type: 'index',
      title: '#',
      width: 80,
      key: 'index',
      align: 'center',
    },
    {
      title: '订单流水号',
      key: 'serialNumber',
      align: 'center',
      width: 220,
      render: (h, params) => {
        return  !self.$authority("ORDER-1-205")?h('div',params.row.serialNumber):
          h('div', [h('a', {
            style:{fontSize:"0.8rem"},
            on: {
              click: () => {
                self.showOrderDetail(params.row.id);
              }
            }
          }, params.row.serialNumber),
          ]) ;
      }
    },
    {
      title: '订单状态',
      key: 'state',
      align: 'center',
      width: 180,
      render: (h, params) => {
        return h('div', self.orderStateDict.filter(item => item.value == params.row.state)[0].name);
      }
    },
    // {
    //   title: '用户',
    //   key: 'userName',
    //   align: 'center',
    //   width: 150,
    //   render: (h, params) => {
    //     // let hideName = Vue.prototype.$tiyHideUsername(params.row.userName);
    //     if(self.$authority("ORDER-1-218")){
    //       return(
    //         <div>
    //           <Tooltip content={params.row.encodeName} placement="top">{params.row.encodeName}</Tooltip>
    //         </div>
    //       );
    //     } else {
    //       return (
    //         <div>
    //           <Tooltip content={params.row.encodeName} placement="top">
    //             {params.row.encodeName}
    //           </Tooltip>
    //         </div>
    //       );
    //     }
    //   }
    // },
    {
      title: '国家',
      key: 'countryName',
      align: 'center',
      width: 160
    },
    {
      title: '付款时间',
      key: 'checkoutTime',
      width: 160,
      render: (h, params) => {
        let checkoutTime = '';
        if(params.row.checkoutTime){
          checkoutTime = self.$tiyBJTime(params.row.checkoutTime);
        }else {
          checkoutTime = '';
        }
        return h("div",
          {
            style: {fontSize: "0.8rem"},
          },
          checkoutTime
        );
      }
    },
    {
      title: '金额',
      key: 'actualPayment',
      align: 'center',
      width: 140,
      render: (h, params) => {
        return h('div', '$'+params.row.actualPayment);
      }
    }
  ];
};

let cartTable = function (self) {
  return [
    {
      type: 'index',
      title: '#',
      width: 60,
      key: 'index',
      align: 'center',
    },
    {
      title: '产品编码',
      key: 'productCode',
      align: 'center',
      width: 180,
      render: (h, params) => {
        let productUrl = Vue.prototype.$tiyProductUrl(params.row.productCode);
        return h('div',[h('a',{
          attrs:{href:productUrl,target:'_blank'}
        },params.row.productCode)]);
      }
    },
    {
      title: '产品图片',
      key: 'colorJson',
      align: 'center',
      width: 100,
      render: (h, params) => {
        {
          let image = params.row.productImgUrl;
          let yunPath = Vue.prototype.$store.getters.imgPrefix;
          return h('div', [h('img', {
            attrs: {src: yunPath + image, height: 60},
            on: {
              click: () => {
                status.modalImage.url = yunPath + image;
                status.modalImage.isShow = true;
              }
            }
          }, image)
          ]);
        }
      }
    },
    {
      title: '色卡',
      key: 'color',
      align: 'center',
      width: 160,
    },
    {
      title: '尺码规格',
      key: 'sizeName',
      align: 'center',
      width: 120,
    },
    // {
    //   title: '状态',
    //   key: 'state',
    //   align: 'center',
    //   width: 100,
    //   render: (h, params) => {
    //     let state = '';
    //     if (params.row.state == 100) {
    //       state = '已上架';
    //     } else if (params.row.state == 200) {
    //       state = '已下架';
    //     } else {
    //       state = '回收站';
    //     }
    //     return h('div',state);
    //   },
    // },
    {
      title: '库存',
      align: 'center',
      key:'stock',
      width: 80,
    },
    {
      title: '当前售价($)',
      align: 'center',
      key:'price',
      width: 120,
    },
    {
      title: '	数量',
      key: 'amount',
      align: 'center',
      width: 80,
    },
    {
      title: '重量(g)',
      key: 'weight',
      align: 'center',
      width: 120,
    },
    {
      title: '添加时间',
      key: 'createtime',
      align: 'center',
      width: 150,
      render: (h, params) => {
        return h('div', self.$tiyBJTime(params.row.createtime));
      }
    },
    {
      title: "操作",
      align: "center",
      width: 100,
      render(h, params) {
        return h("div", [
          h("Button", {
            props: {type: "primary", size: "small"},
            on: {
              click() {
                self.showProductSupply(params.row);
              }
            }
          }, "查看货源"),
        ]);
      }
    }
  ];
};

let recordTable = function (self){
  return [
    {
      type: 'index',
      title: '#',
      width: 80,
      align: 'center'
    },
    {
      title: '用户名',
      key: 'userName',
      width: 150,
      align: 'center',
      render: (h, params) => {
        let username = Vue.prototype.$tiyHideUsername(params.row.userName);
        return h('span', username);
      }
    },
    {
      title: '登录时间',
      key: 'optTime',
      align: 'center',
      minWidth:200,
      render: (h, params) => {
        var date = new Date(params.row.optTime);
        return h('div', self.$tiyBJTime(params.row.optTime));
      }
    },
    {
      title: 'app版本',
      key: 'version',
      align: 'center',
      minWidth:100,
    },
    {
      title: '终端类型',
      key: 'deviceType',
      align: 'center',
      minWidth:100,
      render: (h, params) => {
        let device = '';
        switch(params.row.deviceType){
          case 1:
            device = 'Android';
            break;
          case 2:
            device = 'IOS';
            break;
          case 3:
            device = 'PC';
            break;
          case 4:
            device = 'Mobile PC';
            break;
          default:
            device = '';
            break;
        }
        return h('div', device);
      }
    },
  ];
};

export default {
  tPage: page,
  tStatus: status,
  tParams: params,
  tData: data,
  productTable: productTable,
  orderTable: orderTable,
  searchInfoPage: searchInfoPage,
  cartTable: cartTable,
  recordTable: recordTable
};
